#define _CRT_SECURE_NO_WARNINGS 1


#include <stdio.h> 
#include <math.h>

int main()
{
	int ch[1001][3] = { 0 };
	int sum[1001] = { 0 };
	int n;
	int count = 0;
	scanf("%d", &n);
	int i = 0;
	for (i = 0; i < n; i++)
	{
		scanf("%d%d%d", &ch[i][0], &ch[i][1], &ch[i][2]);
		sum[i] = ch[i][0] + ch[i][1] + ch[i][2];
	}
	int j = 0;
	int l = 0;

	for (j = 0; j < n; j++)
	{
		for (l = 1 + j; l < n; l++)
		{
			if (abs(ch[l][0] - ch[j][0]) <= 5 && abs(ch[l][1] - ch[j][1])<= 5 && abs(ch[l][2] - ch[j][2]) <= 5 && abs(sum[l] - sum[j]) <= 10)
			{
				count++;
			}
		}
	}
	printf("%d", count);
	return 0;
}